package com.l.im.init;

/**
 * @program: LIM
 * @description:
 * @author: Alex Wu
 * @createDate: 2025-04-14 18:00
 **/
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;

import java.util.List;

@Slf4j
public class ZookeeperConnector {

    private final CuratorFramework curatorFramework;

    public ZookeeperConnector(CuratorFramework curatorFramework) {
        this.curatorFramework = curatorFramework;
    }

    // 监听 /ws/nodes/ 路径下的所有子节点变化
    public void watchNodes(String path, PathChildrenCacheListener listener) throws Exception {
        PathChildrenCache cache = new PathChildrenCache(curatorFramework, path, true);
        cache.getListenable().addListener(listener);
        cache.start();
        log.info("Started listening to path: " + path);
    }

    public CuratorFramework getCuratorFramework() {
        return curatorFramework;
    }
}
